package com.xiaofeng.springboot.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * redis配置
 * @author chenzf
 * @date 2017年7月27日
 */
@Configuration
//切换使用别的缓存在SpringBootStartApplication 打开注解@EnableCaching
@EnableCaching
@SuppressWarnings("static-method")
public class RedisConfig {

	@Bean
	public CacheManager cacheManager(RedisTemplate<?, ?> redisTemplate) {
		RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
		//设置缓存过期时间
		cacheManager.setDefaultExpiration(70);//秒
		return cacheManager;
	}

}
